package com.controllers;

import com.services.FileService;
import java.io.File;
import java.io.FileNotFoundException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Controller;

@Controller
public class StorageController {

  @Autowired
  private FileService storage;

  public FileSystemResource getFile(String filename, HttpServletResponse response) throws FileNotFoundException {
    File file = storage.getFileFromStorage(filename);
    response.setHeader("Content-Disposition", "attachment;filename=" + filename);
    return new FileSystemResource(file);
  }

}
